<html>
<head>
	<link rel="stylesheet" type="text/css" href="flot/styles.css" />
		
	<script language="javascript" type="text/javascript" src="/flot/jquery.js"></script>
	<script language="javascript" type="text/javascript" src="/flot/jquery.flot.js"></script>
	<script language="javascript" type="text/javascript" src="/flot/jquery.flot.selection.js"></script>
	<title>Steinman Hall C11: String 0001 - Real Time Monitoring and Control</title>
	
</head>
<!-- 	</section>

<section style="width:15%;float:left"> -->

<body>
	<section id="page"> <!-- Defining the #page section with the section tag -->

        <header> <!-- Defining the header section of the page with the appropriate tag -->
        
            <hgroup>
                <h1>CUNY Energy Institute</h1>
                <h3>Steinman Hall C11: String 0001 - Real Time Monitoring and Control</h3>
            </hgroup>
                            
            <nav class="clear"> <!-- The nav link semantically marks your main site navigation -->
                <ul>
                    <li><a href="realtime">Real Time Monitoring and Control</a></li>
                    <li><a href="plotter">Log</a></li>
                </ul>
            </nav>
        
    	</header>

	<div class="line"></div>  <!-- Dividing line -->
	
	<section id="articles" style="width:67%;float:left"> <!-- A new section with the articles -->
     
            <article id="article1">
	
				<h2>Realtime Performance Monitoring</h2>
				
				<div class="line"></div>
        
				<div id="plots" class="plots">
					<div id="flot_all" class="plot"></div><div id="flot_load"/><div id="flot_meter"/><div id="flot_power"/>
				</div>
			</article>
		</section>
		
		<section style='width:15%;float:right'>
			<article>
				
			<h2>Control</h2>
			<div class="line"></div>
			<form id="control" action="/control" name="control" method="post">
	       	<div>
				<div id="cont" class=inline>
	            <label>Invert Threshold (kW): </label><br />
	            <input type="text" id="c_invert_threshold" name="c_invert_threshold" style="height:30px;width:50px;padding:0 5 0 5"></input><br /><br />
				<label>Charge Threshold (kW): </label> <br />
				<input type="text" id="c_charge_threshold" name="c_charge_threshold" style="height:30px;width:50px;padding:0 5 0 5"></input><br /><br />
				<label>Charge Status</label><br />
				<select id="c_charge_state" name="c_charge_state">
						<option value=0 /> Charge Off </option>
						<option value=1 /> Charge On  </option>
					</select><br /><br />
				<label>Max Charge Current (Amp) </label><br />
				<input type="text" id="c_max_charge_current" name="c_max_charge_current" style="height:30px;width:50px;padding:0 5 0 5"></input><br /><br />
				<label>Sell Status</label><br />
				<select id="c_sell_state" name="c_sell_state">
					<option value=0 /> Sell Off </option>
					<option value=1 /> Sell On  </option>
				</select><br /><br />
				<label>Max Sell Current (Amp) </label><br />
				<input type="text" id="c_max_sell_current" name="c_max_sell_current" style="height:30px;width:50px;padding:0 5 0 5"></input><br /><br />
				<label>Select what MODE you want: </label>
				<select id="c_status" name="c_status">
				<option value=0 /> Manual Configuration</option>
				<option value=1 /> Autopilot </option>
				</select>
				<br /><br />
				<input type="button" value="SAVE" onclick="controlForm()" style="height:40px;width:100px"></input>
				</div> 
	        </div>
			</form>
			</div>
			
		</article>
	</section>
	
	<section style= "width:15%;float:right;padding-right:30px">

		<article>
			<h2>Pb - Acid Sensors</h2>
			<div class="line"></div>
			<div id="sens" class=inline>
					AC Sell Power (Watts)<br>
					<table>
						<tr><td style="width:65px">P 1</td><td style="width:65px">P 2</td><td style="width:65px">P 3</td><td style="width:65px">Total</td></tr>
						<tr><td><span id="s_poac0"></span></td><td><span id="s_poac1"></span></td><td><span id="s_poac2"></span></td><td><span id="s_tpoac"></span></td></tr>
					</table>
				<br>
				AC Charge Power (Watts)<br>
				<table>
					<tr><td style="width:65px">P 1</td><td style="width:65px">P 2</td><td style="width:65px">P 3</td><td style="width:65px">Total</td></tr>
					<tr><td><span id="s_piac0"></span></td><td><span id="s_piac1"></span></td><td><span id="s_piac2"></span></td><td><span id="s_tpiac"></span></td></tr>
				</table>	
				<br>
				Invert Current (A)<br>
				<table>
					<tr><td style="width:65px">I 1</td><td style="width:65px">I 2</td><td style="width:65px">I 3</td><td style="width:65px">Total</td></tr>
					<tr><td><span id="s_iac0"></span></td><td><span id="s_iac1"></span></td><td><span id="s_iac2"></span></td><td><span id="s_Aiac"></span></td></tr>
				</table>
				<br>
				Charge Current (A)<br>
				<table>
					<tr><td style="width:65px">I 1</td><td style="width:65px">I 2</td><td style="width:65px">I 3</td><td style="width:65px">Total</td></tr>
					<tr><td><span id="s_idc0"></span></td><td><span id="s_idc1"></span></td><td><span id="s_idc2"></span></td><td><span id="s_Aidc"></span></td></tr>
				</table>
				<br>
				AC Voltage (V)<br>
				<table>
					<tr><td style="width:65px">V 1</td><td style="width:65px">V 2</td><td style="width:65px">V 3</td><td style="width:65px">V 4</td></tr>
					<tr><td><span id="s_vac0"></span></td><td><span id="s_vac1"></span></td><td><span id="s_vac2"></span></td><td><span id="s_vac3"></span></td></tr>
				</table>
				<br>
				Battery Voltage (V)<br>
				<table>
					<tr><td style="width:65px">V 1</td><td style="width:65px">V 2</td><td style="width:65px">V 3</td><td style="width:65px">Sys. Total</td></tr>
					<tr><td><span id="s_vdc0"></span></td><td><span id="s_vdc1"></span></td><td><span id="s_vdc2"></span></td><td><span id="s_SysTot"></span></td></tr>
				</table>
				<br>
				State Of Charge (0-100)<br>
				<table>
					<tr><td style="width:65px">SOC 1</td><td style="width:65px">SOC 2</td><td style="width:65px">SOC 3</td><td style="width:65px">SOC 4</td></tr>
					<tr><td><span id="s_soc0"></span></td><td><span id="s_soc1"></span></td><td><span id="s_soc2"></span></td><td><span id="s_soc3"></span></td></tr>
				</table>
				<br>
				Temperature (C)<br>
				<table>
					<tr><td style="width:65px">T 1</td><td style="width:65px">T 2</td><td style="width:65px">T 3</td><td style="width:65px">T 4</td></tr>
					<tr><td><span id="s_temperature0"></span></td><td><span id="s_temperature1"></span></td><td><span id="s_temperature2"></span></td><td><span id="s_temperature3"></span></td></tr>
				</table>
				<br>
				Amp Hours<br>
				<table>
					<tr><td style = "width:65px">Charge</td><td style="width:65px">Discharge</td></tr>
					<tr><td><span id="s_TotCharAH"></td><td><span id="s_TotSellAH"></td></tr>
				</table>
			
				<br /><br /><br />
			</div>
			
			<h2>Ni-Zn Sensors</h2>
			<div class="line"></div>
			<div id="sens" class=inline>
				Temperature (C)<br>
				<table>
					<tr><td style="width:65px">T 1</td><td style="width:65px">T 2</td><td style="width:65px">T 3</td><td style="width:65px">T 4</td></tr>
					<tr><td><span id="s_temperature0"></span></td><td><span id="s_temperature1"></span></td><td><span id="s_temperature2"></span></td><td><span id="s_temperature3"></span></td></tr>
				</table>
				<br>
				Voltage (V)<br>
				<table>
					<tr><td style="width:65px">V 1</td><td style="width:65px">V 2</td><td style="width:65px">V 3</td><td style="width:65px">V 4</td><td style="width:65px">Total</tr>
					<tr><td><span id="s_Niv0"></span></td><td><span id="s_Niv1"></span></td><td><span id="s_Niv2"></span></td><td><span id="s_Niv3"></span></td><td><span id="s_TNiv"></tr>
				</table>
				
			</div>

		</article>
				
					
	</section>
    
	</section> <!-- Closing the #page section -->


</body>

<script src="/flot/build_dom.js"></script>
<script src="/flot/functions.js"></script> 
<script>

function controlForm() {
	var str="charge_threshold=" + $('#c_charge_threshold').val() + 
			"&invert_threshold=" + $('#c_invert_threshold').val() +
			"&max_charge_current=" +$('#c_max_charge_current').val() + 
			"&max_sell_current=" +$('#c_max_sell_current').val() +
			"&charge_state=" + $('#c_charge_state').val() +
			"&sell_state=" + $('#c_sell_state').val() +
			"&status=" + $('#c_status').val() 
	manageControl(str,'/writecontrol')
}

sensors = $("[id^=s_]")
stuffs = $("[id^=flot_]")
field_json = {'time':1}
sensors_json = {}

for (var i = 0; i < stuffs.length; i++)
{
	if (stuffs[i].id != undefined) 
	{
		field_json[stuffs[i].id.replace("flot_","")] = 1
	}
}

for (var i = 0; i < sensors.length; i++)
{
	if (sensors[i].id != undefined) 
	{
		sensors_json[sensors[i].id.replace("s_","")] = 1
	}
}

db_to_get = "realtime"
db_to_get_sensors = "sensors"


grabData({collection:db_to_get,query:{'time':{'$gt':new Date().getTime()-24*60*60*1000,'$lt':new Date().getTime()}},fields:field_json},1)
grabSensors({collection:db_to_get_sensors,query:{},fields:sensors_json})
manageControl('','/readcontrol')

setInterval(function(){grabData({collection:db_to_get,query:{'time':{'$gt':new Date().getTime()-24*60*60*1000,'$lt':new Date().getTime()}},fields:field_json},1)},5000)
setInterval(function(){grabSensors({collection:db_to_get_sensors,query:{},fields:sensors_json})},5011)
setInterval(function(){manageControl('','/readcontrol')},10013)

</script>
<script src="flot/script.js"></script>
</html>